﻿using System;
using System.IO;
using System.Security.Principal;

namespace MyHostSwtich.Core
{
    public class Utils
    {
        public static Utils Instance { get; private set; } = new Utils();

        private Utils()
        {
        }

        /// <summary>
        /// 确定当前主体是否属于具有指定 Administrator 的 Windows 用户组
        /// </summary>
        /// <returns>如果当前主体是指定的 Administrator 用户组的成员，则为 true；否则为 false。</returns>
        public bool IsAdministrator()
        {
            bool result;
            try
            {
                var identity = WindowsIdentity.GetCurrent();
                var principal = new WindowsPrincipal(identity);
                result = principal.IsInRole(WindowsBuiltInRole.Administrator);
            }
            catch
            {
                result = false;
            }
            return result;
        }

        public string GetHostPath()
        {
            var sysPath = Environment.GetFolderPath(Environment.SpecialFolder.System);
            var etcPath = Path.Combine(sysPath, @"drivers\etc\");
            var ret = Path.GetFullPath(etcPath);
            return ret;
        }

    }

}
